home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************************************
- *
- *
- * ObjectMacZapp -- a standard Mac OOP application template
- *
- *
- *
- * ZCommander.cpp -- an object for handling commands
- *
- *
- *
- *
- *
- * © 1996, Graham Cox
- *
- *
- *
- *
- *************************************************************************************************/
-
- #include "ZCommander.h"
- #include "ZObjectArray.cpp"
- #include "MacZoop.h"
-
-
- /*----------------------------------*** CONSTRUCTOR ***----------------------------------*/
-
- ZCommander::ZCommander( ZCommander* aBoss )
- : ZComrade()
- {
- itsBoss = aBoss;
- itsUnderlings = NULL;
-
- if ( itsBoss )
- itsBoss->AddUnderling( this );
- }
-
- /*-----------------------------------*** DESTRUCTOR ***----------------------------------*/
-
- ZCommander::~ZCommander()
- {
- // dispose of any objects whose boss this is
-
- if ( itsUnderlings )
- itsUnderlings->DisposeAll();
-
- // remove us from our boss
-
- if ( itsBoss )
- itsBoss->RemoveUnderling( this );
- }
-
-
- /*-------------------------------*** HANDLECOMMAND ***---------------------------------*/
- /*
-
- if it has a boss, it passes the command to it for handling
- ----------------------------------------------------------------------------------------*/
-
- void ZCommander::HandleCommand( const short menuID, const short itemID )
- {
- if ( itsBoss )
- itsBoss->HandleCommand( menuID, itemID );
- }
-
-
- /*-------------------------------*** HANDLECOMMAND ***--------------------------------*/
- /*
- pass command object to boss if there is one
- ----------------------------------------------------------------------------------------*/
-
- void ZCommander::HandleCommand( const long theCommand )
- {
- // pass edit menu commands to the local handler methods. It is easier to override
- // those methods than to override this method, but the choice is yours.
-
- switch ( theCommand )
- {
- case kCmdCut:
- DoCut();
- break;
- case kCmdCopy:
- DoCopy();
- break;
- case kCmdPaste:
- DoPaste();
- break;
- case kCmdClear:
- DoClear();
- break;
- case kCmdSelectAll:
- DoSelectAll();
- break;
- default:
- if ( itsBoss )
- itsBoss->HandleCommand( theCommand );
- break;
- }
- }
-
-
- /*-------------------------------*** UPDATEMENUS ***---------------------------------*/
- /*
-
- if it has a boss, it asks it to update its menus
-
- ----------------------------------------------------------------------------------------*/
-
- void ZCommander::UpdateMenus()
- {
- // enable the paste command if there is something this object can
- // paste.
-
- if ( CanPasteType())
- gMenuBar->EnableCommand( kCmdPaste );
-
- if ( itsBoss )
- itsBoss->UpdateMenus();
- }
-
-
-
- /*-----------------------------*** HANDLEAPPLEEVENT ***-------------------------------*/
- /*
-
- if it has a boss, it passes the command to it for handling. Override this to process
- apple events you are interested in, call the inherited method for others.
- ----------------------------------------------------------------------------------------*/
-
- void ZCommander::HandleAppleEvent( AEEventClass aeClass, AEEventID aeID,
- AppleEvent* aeEvt, AppleEvent* reply )
- {
- if ( itsBoss )
- itsBoss->HandleAppleEvent( aeClass, aeID, aeEvt, reply );
- else
- FailOSErr( errAEEventNotHandled );
- }
-
-
- /*-----------------------------------*** IDLE ***-------------------------------------*/
- /*
-
- called periodically if this is in the chain of command. It passes the call up to its boss.
-
- ----------------------------------------------------------------------------------------*/
-
- void ZCommander::Idle()
- {
- if ( itsBoss )
- itsBoss->Idle();
- }
-
-
- /*-----------------------------------*** TYPE ***-------------------------------------*/
- /*
-
- this user is typing while this commander is active
-
- ----------------------------------------------------------------------------------------*/
-
- void ZCommander::Type( const char theKey )
- {
- if ( itsBoss )
- itsBoss->Type( theKey );
- }
-
-
- /*-------------------------------*** ADDUNDERLING ***---------------------------------*/
- /*
- adds <anUnderling> to its list of underlings
- ----------------------------------------------------------------------------------------*/
-
- void ZCommander::AddUnderling( ZCommander* anUnderling )
- {
- if ( itsUnderlings == NULL )
- FailNIL( itsUnderlings = new ZCommanderList());
-
- itsUnderlings->AppendItem( anUnderling );
- }
-
- /*-----------------------------*** REMOVEUNDERLING ***--------------------------------*/
- /*
- removes <anUnderling> from its list of underlings
- ----------------------------------------------------------------------------------------*/
-
- void ZCommander::RemoveUnderling( ZCommander* anUnderling )
- {
- if ( itsUnderlings && itsUnderlings->Contains( anUnderling ))
- {
- itsUnderlings->DeleteObject( anUnderling );
-
- if ( itsUnderlings->CountItems() < 1 )
- ForgetObject( itsUnderlings );
- }
- }
-
- /*--------------------------------*** SENDMESSAGE ***---------------------------------*/
- /*
- send the message to the boss as well as any nominated listeners
- ----------------------------------------------------------------------------------------*/
-
- void ZCommander::SendMessage( long aMessage, void* msgData )
- {
- // we always send this message to our boss
-
- if ( itsBoss )
- itsBoss->ReceiveMessage( this, aMessage, msgData );
-
- inherited::SendMessage( aMessage, msgData );
- }
-
-
- /*--------------------------------*** SENDMESSAGE ***---------------------------------*/
- /*
- send the message to the boss as well as any nominated listeners
- ----------------------------------------------------------------------------------------*/
-
- void ZCommander::SendMessage( ZMessage* aMessage )
- {
- // we always send this message to our boss
-
- if ( itsBoss )
- itsBoss->ReceiveMessage( this, aMessage );
-
- inherited::SendMessage( aMessage );
- }
-
-
-